import { Component, OnInit } from '@angular/core';
import { ActivatedRoute } from '@angular/router';
import { NzModalService } from 'ng-zorro-antd';

declare var form: any;

@Component({
  templateUrl: './data.input.info.component.html'
})
export class DataInputInfoComponent implements OnInit {

  // 当前数据
  fs: any;

  constructor(
    public route: ActivatedRoute,
    private modalService: NzModalService) {

    this.fs = new form.FormSimpleService('checkhistory', {
      orderObject: { lastTime: 1 },
      keyField: 'id',
      randomFields: ['id'],
      defaultQueryObject: { type: '数据导入' }
    });

  }

  ngOnInit() {
    this.initData();

    // 浏览器关闭监听
    window.onbeforeunload = () => {
      // tslint:disable-next-line: deprecation
      const e: any = window.event;
      e.returnValue = ('请确认已保存，是否离开？');
      return e;
    };
  }

  initData() {
    let id = '-1';
    this.route.queryParams.subscribe((res) => {
      if (res.id) {
        id = res.id;
      }
    });
    this.fs.editRowByKey(id);
  }

  close() {
    window.close();
  }
}
